package com.grieous.dao.impl;

import java.util.List;
import java.util.Map;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

import com.grieous.dao.UserDao;
import com.grieous.domain.User;

@Repository
public class UserDaoImpl extends SqlSessionDaoSupport implements UserDao {

	@Override
	public void insertUser(User user) {
		getSqlSession().insert("mybatis.mapper.UserMapper.insertSelective",user);

	}

	@Override
	public void updateUser(User user) {
		getSqlSession().update("mybatis.mapper.UserMapper.updateByPrimaryKeySelective",user);

	}

	@Override
	public void deleteUser(Integer id) {
		getSqlSession().delete("mybatis.mapper.UserMapper.deleteByPrimaryKey",id);

	}

	@Override
	public List<User> getUser(Map<String, Object> map) {
		List<User> list = getSqlSession().selectList(
				"mybatis.mapper.UserMapper.getUser", map);
		return list;
	}

	@Override
	public int getUserCount(Map<String, Object> map) {
		Object obj = getSqlSession().selectOne(
				"mybatis.mapper.UserMapper.getUserCount", map);
		return (Integer) (obj == null ? 0 : obj);
	}

}
